## Utils
### aui.utils.run [> 1.7.15]
执行一段表达式  可以使用加减乘除

```javascript
aui.utils.run = function(expression, context = window) {
    return Function.apply(Function, ['context', `with(context) { return ${expression} }`])(context, expression);
}
```

example
```javascript
aui.utils.run(`a - b`, {
    a: 2,
    b: 1
}); // 1
```

### aui.utils.deepAssign

使用lodash/merge

/**
 *  @example
 *
 * var object = {
 *   'a': [{ 'b': 2 }, { 'd': 4 }]
 * };
 *
 * var other = {
 *   'a': [{ 'c': 3 }, { 'e': 5 }]
 * };
 *
 * _.merge(object, other);
 * // => { 'a': [{ 'b': 2, 'c': 3 }, { 'd': 4, 'e': 5 }] }
 */
 
<!-- 
### aui.utils.deepMerge [> 1.0.1]
深度merge对象


example
```javascript
aui.utils.deepMerge.all([{}, {a: 1}])
``` -->

### aui.utils.setData [> 1.9.1]
设置对象by path

example
```javascript
aui.utils.setData = function(target, define) {
    let ret = target;
    for (let definekey in define) {
        ret = Object.auiSetByPath(ret, definekey, define[definekey]);
    }
    return ret;
};
```

### aui.utils.transformStylelikeExp [> 1.9.16]

##### 使用范围

node,browser,xcx

转变类似标签上css style语法

```javascript
/**
 * 转变类似标签上css style语法
 * 
 * @param {String} str 
 * @param {String} [splitopr = ;] 
 * 
 * @example
 * 'translateX:100;' => [['translateX', '100']]
 * 
 * @return {Array} arr
 */
export function transformStylelikeExp(str, splitopr = ";") {
    if (!str) {
        return [];
    }
    if (str.endsWith(splitopr)) {
        str = str.slice(0, str.length - 1);
    }    
    let arr = str.split(splitopr);
    arr = arr.map(v => {
        return  v.trim().split(":").map(s => s.trim())
    });
    return arr;
}
```

### aui.utils.chartoUnicode [> 1.8.1]
转换中文到unicode

```javascript
export function chartoUnicode(s){ 
  return s.replace(/([\u4E00-\u9FA5])/g,function(){
    return "\\u" + RegExp["$1"].charCodeAt(0).toString(16);
  });
}
```

### aui.utils.parseObjToOptions [> 1.0.1] <has-tested></has-tested>

解析obj 到options

```
/**
 * parse obj to a option
 *
 * { a: 1 }
 *
 * [
 *     {
 *          name: "a",
 *          value: 1
 *     }
 * ]
 *
 * @param obj
 * @returns {Array}
 */
```

### aui.utils.parseOptionsToObj [> 1.0.1] <has-tested></has-tested>
解析options 到obj

### aui.utils.coalesceFactory [> 1.1.0]
Returns a customized coalesce function that returns the first argument that returns true from the provided argument validation function.

```javascript
const coalesceFactory = valid => (...args) => args.find(valid);
```

example
```javascript
const customCoalesce = coalesceFactory(_ => ![null, undefined, '', NaN].includes(_));
customCoalesce(undefined, null, NaN, '', 'Waldo'); // "Waldo"
```

### aui.utils.getURLParameters [> 1.1.0] <has-tested></has-tested>
Returns an object containing the parameters of the current URL.

```javascript
const getURLParameters = url =>
  (url.match(/([^?=&]+)(=([^&]*))/g) || []).reduce(
    (a, v) => ((a[v.slice(0, v.indexOf('='))] = v.slice(v.indexOf('=') + 1)), a),
    {}
  );
```

example
```javascript
getURLParameters('http://url.com/page?name=Adam&surname=Smith'); // {name: 'Adam', surname: 'Smith'}
getURLParameters('google.com'); // {}
```

### aui.utils.size [ie > 10] [stage 1]
获取变量size 字符串返回字节长度

```javascript
const size = val =>
  Array.isArray(val)
    ? val.length
    : val && typeof val === 'object'
      ? val.size || val.length || Object.keys(val).length
      : typeof val === 'string' ? new Blob([val]).size : 0;
```
example
```javascript
size([1, 2, 3, 4, 5]); // 5
size('size'); // 4
size({ one: 1, two: 2, three: 3 }); // 3
```

### aui.utils.sleep [> 1.0.1] 
js线程强制休眠

```javascript
export function sleep(delay) {
    let start = (new Date()).getTime();
    while ((new Date()).getTime() - start < delay) {
        continue;
    }
}
```

### aui.utils.param [> 1.7.1] <has-tested></has-tested>
类似于$.param

```javascript
function param(a) {
    return Object.keys(a).map(function(k) {
        return encodeURIComponent(k) + '=' + encodeURIComponent(a[k])
    }).join('&');
}
```

### aui.utils.format [stage 1] -> aui.validate.format

